package com.geekaca.iobuffer;

import java.io.*;

public class HelloReaderWriter {
    public static void main(String[] args) {
        /**
         * 字符缓冲流!!!
         */

//        testBufferedReader();
        testBufferedWriter();
    }

    public static void testBufferedReader() {
        try (
                Reader fr = new FileReader("studyIOBuffer\\test.txt");
        ) {
            BufferedReader br = new BufferedReader(fr);

//            String s = br.readLine();
//            System.out.println(s);
//            System.out.println(br.readLine());
//            System.out.println(br.readLine());
//            System.out.println(br.readLine());
//            System.out.println(br.readLine());
//            System.out.println(br.readLine());

            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void testBufferedWriter() {
        try (Writer fw = new FileWriter("studyIOBuffer\\writer.txt")) {
            BufferedWriter bw;
            bw = new BufferedWriter(fw);
            bw.write("hello");
            bw.newLine();
            bw.write("测试");
            bw.write("您好");
            bw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
